package geppetto.cat.constrains;

import geppetto.phraseHMM.Trellis;

import java.util.ArrayList;


public  class SentenceConstrainedProjectionStats {

	public boolean directionNotAscentDirection;
	/** No step was found */
	public boolean noZoomStepFound;
	public boolean noBracketingStepFound;
	public boolean noConvergence;
	public boolean objectiveBecomeNotANumber;
	/** Maximum evaluations for picking a step when a step was actually found*/
	public int maxStepEval=-1;
	
	public ArrayList<Integer> _numberOfSteps;
	
	/** Number of steps to converge */
	public int numberOfProjections;
	/** sentence source len */
	public int sourceLen;
	/** sentene target len */
	public int targetLen;
	/** Posteriors after projections
	 * usefull to look at when no projection was possible 
	 */
	public Trellis posteriors;
	
	/** Sentecen Number*/
	public int sentenceNumber;
	/** Value of the objective after the projection */
	public double objective;
	/** Likelihood before projection */
	public double originalLikelihood;
	/** Likelihood after projection */
	public double likelihood;
	
	/** The sentence already add all the constrains */
	public boolean noConstrains;
	
	/** Number of forward backward*/
	public int fbcall;
	
	/** time spend in projectin*/
	long start = -1;
	long totalTime = 0;
	
	/**lambda*/
	public Trellis lambda ;
	
	
	
//	public SentenceConstrainedProjectionStats(){
//		
//	}
	
	public SentenceConstrainedProjectionStats(int sourceLen, int targetLen, int sentenceNumber) {
		noZoomStepFound = false;
		_numberOfSteps = new ArrayList<Integer>();
		numberOfProjections=0;
		this.sourceLen = sourceLen;
		this.targetLen = targetLen;
		this.sentenceNumber = sentenceNumber;
	}
	
	public String prettyPrint(){
		StringBuffer res = new StringBuffer();
		res.append("Sent. " + sentenceNumber + " SL " + sourceLen + " TL  " + targetLen + " time " + totalTime);
		if(noZoomStepFound){
			res.append( " no step");
		}else{
			res.append( " proj:"+numberOfProjections + " obj " + objective + " orgin likelihood " + originalLikelihood + " new likelihood " + likelihood);
			res.append("\nsteps: ");
			for(int nStep : _numberOfSteps){
				res.append(nStep + " ");
			}
		}
		return res.toString();
	}
	
	public void startTime() {
		start = System.currentTimeMillis();
	}
	public void stopTime() {
		totalTime += System.currentTimeMillis() - start;
	}
	
}
